import 'package:amoy_ticket/utils/object_util.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class HomeTabCommonWidget extends StatefulWidget {
  HomeTabCommonWidget({Key? key}) : super(key: key);

  @override
  _HomeTabCommonWidgetState createState() => _HomeTabCommonWidgetState();
}

class _HomeTabCommonWidgetState extends State<HomeTabCommonWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: null,
    );
  }

  int selectIndex = 0;
  Widget itemWidget(BuildContext context, String imageUrl, String name,
      String time, String space, String distance,
      {String? price}) {
    return Container(
      width: MediaQuery.of(context).size.width / 2 - 20,
      child: Stack(
        children: [
          Column(
            children: [
              Container(
                height: 250,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(6.r),
                  image: DecorationImage(
                    fit: BoxFit.fill,
                    image: CachedNetworkImageProvider(imageUrl),
                  ),
                ),
                // height: 300,
              ),
              Container(
                margin: EdgeInsets.symmetric(horizontal: 5.w, vertical: 5.h),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      name,
                      maxLines: 2,
                      overflow: TextOverflow.ellipsis,
                      style: TextStyle(
                        fontSize: 13.sp,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                    Text(
                      time,
                      style: TextStyle(color: Colors.grey),
                    ),
                    Row(
                      children: [
                        Expanded(
                          child: Text(
                            space,
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                            style: TextStyle(color: Colors.grey),
                          ),
                        ),
                        // SizedBox(width: 3.w),
                        Expanded(
                          child: Text(
                            '${distance}km',
                            style: TextStyle(color: Colors.grey),
                          ),
                        )
                      ],
                    ),
                    ObjectUtil.isNotEmpty(price)
                        ? Row(
                            children: [
                              Text(
                                ObjectUtil.isNotEmpty(price) ? '￥$price' : '',
                                style: TextStyle(
                                    color: Colors.red, fontSize: 14.sp),
                              ),
                              Text(
                                '起',
                                style: TextStyle(color: Colors.grey),
                              ),
                            ],
                          )
                        : Container(
                            height: 15.h,
                          )
                  ],
                ),
              ),
            ],
          ),
          Positioned(
              right: 10.w,
              bottom: 7.h,
              child: Image.asset(
                'assets/images/want_to_see.png',
                width: 15.w,
                height: 15.w,
                color: Colors.black,
              )),
        ],
      ),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(6.r),
      ),
    );
  }

  Widget tabList() {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 12.w),
      child: Row(
        children: [
          _tabWidget('人气', 0),
          _tabWidget('折扣', 1),
          _tabWidget('最近开演', 2),
          _tabWidget('上新', 3),
          _tabWidget('距离', 4),
        ],
      ),
    );
  }

  _tabWidget(String text, int index) {
    return Row(
      children: [
        GestureDetector(
          child: Text(
            text,
            style: selectIndex == index
                ? _selectTextStyle()
                : _unSelectTextStyle(),
          ),
          onTap: () {
            selectIndex = index;
            setState(() {});
          },
        ),
        SizedBox(width: 15.w),
      ],
    );
  }

  _selectTextStyle() {
    return TextStyle(
        fontSize: 12.sp, color: Color(0xFF0f0f0f), fontWeight: FontWeight.bold);
  }

  _unSelectTextStyle() {
    return TextStyle(fontSize: 12.sp, color: Color(0xFF686868));
  }
}
